package edu.kaist.cs408.pof.android.service;

import android.util.Log;
import edu.kaist.cs408.pof.common.model.*;
import edu.kaist.cs408.pof.common.service.*;
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;

import java.util.List;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: duyleekun
 * Date: 5/14/12
 * Time: 9:58 PM
 * To change this template use File | Settings | File Templates.
 */
public class RestServices {
	public final static DishSvc dishSvc;
	public final static KaistianSvc kaistianSvc;
	public final static RestaurantOwnerSvc restaurantOwnerSvc;
	public final static RestaurantSvc restaurantSvc;
	public final static TalkSvc talkSvc;

	static final String baseUrl = "http://pofjas-kaist.rhcloud.com/backend";

	static {
		RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
		dishSvc = ProxyFactory.create(DishSvc.class, baseUrl);
		kaistianSvc = ProxyFactory.create(KaistianSvc.class, baseUrl);
		restaurantSvc = ProxyFactory.create(RestaurantSvc.class, baseUrl);
		restaurantOwnerSvc = ProxyFactory.create(RestaurantOwnerSvc.class, baseUrl);
		talkSvc = ProxyFactory.create(TalkSvc.class, baseUrl);
	}

	private void runTest() {
		List<RestaurantVo> allRestaurants = RestServices.restaurantSvc.get(null);
		Log.i("mainact", "All rest work");


		List<RestaurantVo> openRestaurants = RestServices.restaurantSvc.get(1);
		Log.i("mainact", "All open rest ok");

		RestaurantVo someRestaurant = allRestaurants.get(0);
		Log.i("mainact", "get some restaurant ok");

		DishVo someDish = someRestaurant.getDishes().get(0);
		Log.i("mainact", "get some dish ok");

		RestServices.kaistianSvc.create(new KaistianVo("test user" + UUID.randomUUID(), "password from android"));
		Log.i("mainact", "create a user ok");

		KaistianVo someKaistian = RestServices.kaistianSvc.login("Super Kaistian 0582757d-a9de-4099-917a-a1f50ac3de4b", "Super Kaistian password");
		Log.i("mainact", "login ok");

		RestServices.restaurantSvc.addDish(new DishVo("new dish from android" + UUID.randomUUID(), 1000), someRestaurant.getMid());
		Log.i("mainact", "create new dish ok");

		RestServices.restaurantSvc.rate(someRestaurant.getMid(), 5);
		Log.i("mainact", "rate restaurant ok");

		RestServices.restaurantSvc.postTalk(someRestaurant.getMid(), someKaistian.getMid(), new TalkVo("posted from android"));
		Log.i("mainact", "talk ok");


		List<TalkVo> allTalk = RestServices.talkSvc.getAll(0, 0);
		Log.i("mainact", "get all talk ok");

		RestServices.restaurantOwnerSvc.create(new RestaurantOwnerVo("test owner" + UUID.randomUUID(), "password from android owner"));
		Log.i("mainact", "new Owner ok");
	}

}
